﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using TugasAkhir.Helpers;
using TugasAkhir.Objects;

namespace TugasAkhir.Models
{
    public static class MahasiswaModel
    {
        public static bool GetMahasiswaDetail(string nrp, out MahasiswaObject mahasiswa)
        {
            var hasilQuery = new DataSet();
            string query = String.Format("SELECT * FROM [dbo].[mahasiswa] WHERE [NRP] = '{0}'", nrp);
            bool flag = SqlServer.ExecuteReader(query, out hasilQuery);

            if (flag)
            {
                if (hasilQuery.Tables[0] != null && hasilQuery.Tables[0].Rows.Count > 0)
                {
                    mahasiswa = new MahasiswaObject();
                    mahasiswa.IdMahasiswa = hasilQuery.Tables[0].Rows[0][0].ToString();
                    mahasiswa.Nrp = hasilQuery.Tables[0].Rows[0][1].ToString();
                    mahasiswa.Nama = hasilQuery.Tables[0].Rows[0][2].ToString();
                    return true;
                }
                else
                {
                    mahasiswa = new MahasiswaObject();
                    return false;
                }
            }
            else
            {
                mahasiswa = new MahasiswaObject();
                return false;
            }
        }
    }
}